//
//  PaymentTypeCell.m
//  ImGuider
//
//  Created by 王鹏宇 on 2017/12/13.
//  Copyright © 2017年 AudioCtrip. All rights reserved.
//

#import "PaymentTypeCell.h"
#import "PaymentCell.h"
@implementation PaymentTypeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self.paymentTableView registerNib:[UINib nibWithNibName:@"PaymentCell" bundle:nil] forCellReuseIdentifier:@"PaymentCell"];
    
    self.payMentLabel.text = [NSString stringWithFormat:@"%@:",MYLocalizedString(@"PAYORDER_TYPE", nil)];
    self.paymentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.paymentTableView.scrollEnabled = NO;
    self.selectionStyle =  UITableViewCellSelectionStyleNone;
    [self setupDataSource];
}

- (void)setupDataSource {
    
    //    if([[AppManager sharedManager].currencyCode isEqualToString:@"USD"]){
    //        self.dataSource = [NSMutableArray arrayWithArray:@[@{@"icon":@"palpay",@"payMentWay":@"PayPal",@"payType":@(PayTypePaypal)}]];
    //    }else{
    //
    //    }
    
    self.dataSource = [NSMutableArray arrayWithArray:@[@{@"icon":@"alipay",@"payMentWay":MYLocalizedString(@"PAYORDER_TYPE_ALIPAY", nil),@"payType":@(PayTypeAlipay)},@{@"icon":@"wepay",@"payMentWay":MYLocalizedString(@"PAYORDER_TYPE_WX", nil),@"payType":@(PayTypeWX)}]];
    
    [self.paymentTableView reloadData];
}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataSource.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    PaymentCell * cell = [tableView dequeueReusableCellWithIdentifier:@"PaymentCell"];
    
    NSDictionary * dict = self.dataSource[indexPath.row];
    
    [cell configDataWithDict:dict];
    
    if (indexPath.row == 0) {
        NSNumber * payType = dict[@"payType"];
        cell.select = YES;
        self.currentIndexPath = indexPath;
        if (_delegate && [_delegate respondsToSelector:@selector(seletedPayType:)]) {
            
            [_delegate seletedPayType: payType.integerValue];
        }
    }
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 50;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (self.currentIndexPath) {
        
        PaymentCell * cell = [tableView cellForRowAtIndexPath:self.currentIndexPath];
        
        cell.select = NO;
    }
    
    PaymentCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    
    cell.select = YES;
    self.currentIndexPath = indexPath;
    
    NSNumber * payType = self.dataSource[indexPath.row][@"payType"];
    if (_delegate && [_delegate respondsToSelector:@selector(seletedPayType:)]) {
        
        [_delegate seletedPayType: payType.integerValue];
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

